import {browserHistory} from 'dva/router';

function islogin() {
    var user = JSON.parse(sessionStorage.getItem('user'));
    //console.log(user);
    if (!user) {
        //console.log('未登陆islogin!');
        browserHistory.replace('/login');
        return false;
    } else {
        return true;
    }
}

function Check() {}
Check.checkpage = function (pagename) {
    if (islogin()) {
        var user = JSON.parse(sessionStorage.getItem('user'));
        //console.log(user.Roles);
        if (user.Roles.includes('省级客服角色')) {
            if ((pagename === '申请退款') || (pagename === '订单列表')) {
                return true;
            }
        }
    }

    return false;

}

Check.checkrole = function (role) {
    if (islogin()) {
        var user = JSON.parse(sessionStorage.getItem('user'));
        //console.log(user.Roles);
        if (user.Roles.includes(role)) {

            return true;
        }
    }
    return false;
}

export default Check;
